<template>
	<view style="padding: 30rpx;">
		<button @click="callSetStorage()">SetStorage</button>
		<button @click="callGetStorage()">获取缓存</button>
		<button @click="callStoInfo()" type="primary">获取字段列表</button>
		<button @click="callRemove()" type="warn" plain="true">删除</button>
		<button @click="onClear()" type="warn">清空</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			callSetStorage() {
				console.log("callSetStorage==> userName yehuang");
				uni.setStorage({
					key: "userName",
					data: "yehuang",
					success(res) {
						console.log("存储userName 成功回调");
					},
					fail() {
						console.error("存储userName 回调失败");
					}
				})
			},
			callGetStorage() {
				uni.getStorage({
					key: "userName",
					success: function(result) {
						console.log("获取本地缓存成功 result.data:" + result.data);
					},
					fail: function(result) {
						console.error("获取本地缓存失败" + JSON.stringify(result));
						console.error("获取本地缓存失败" + reault.errMsg);
					}
				})
			},
			callStoInfo() {
				uni.getStorageInfo({
					success: function(res) {
						console.log(res.keys);
						console.log(res.currentSize);
						console.log(res.limitSize);
					}
				})
			},
			callRemove() {
				uni.removeStorage({
					key: "userName", // 要删除的缓存键名
					success() {
						console.log("删除指定缓存成功");
					},
					fail() {
						console.error("删除指定缓存失败");
					}
				});
			},
			onClear() {
				uni.clearStorage({
					success() {
						console.log("清空所有缓存成功");
					},
					fail() {
						console.error("清空所有缓存失败");
					}
				});
			}
		}
	}
</script>

<style>
	button {
		margin: 30rpx;
	}
</style>